package com.woniu.shirocore;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.env.BasicIniEnvironment;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;

/**
 * 登录认证的基础demo
 *
 * @author WenXin
 * @version 1.0
 * @description: TODO
 * @date 2022/9/5 15:03
 */
public class LoginAuthBasicDemo {

    public static void main(String[] args) {
        //读取配置文件
        BasicIniEnvironment basicIniEnvironment = new BasicIniEnvironment("classpath:ini/shiro-auth.ini");
        //获取中央大脑securityManager
        SecurityManager securityManager = basicIniEnvironment.getSecurityManager();
        //将中央大脑装配进SecurityUtils工具类中，securityManager
        SecurityUtils.setSecurityManager(securityManager);
        //通过工具类获取Subject对象
        Subject subject = SecurityUtils.getSubject();
        subject.login(new UsernamePasswordToken("wenxin", "123456"));
        //如果登录成功，以下结果为true  isAuthenticated是否通过认证
        System.out.println(subject.getPrincipals() + "是否登录成功" + subject.isAuthenticated());
    }
}
